package com.ruoyi.project.system.strategy.controller;

import java.util.List;

import com.ruoyi.project.system.jgg.domain.TbBaseCustomIndexDef;
import com.ruoyi.project.system.jgg.domain.TbBaseJgg;
import com.ruoyi.project.system.jgg.service.ITbBaseJggService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.strategy.domain.TbDiyStrategy;
import com.ruoyi.project.system.strategy.service.ITbDiyStrategyService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 策略生成Controller
 * 
 * @author ruoyi
 * @date 2021-12-28
 */
@Controller
@RequestMapping("/system/strategy")
public class TbDiyStrategyController extends BaseController
{
    private String prefix = "system/strategy";

    @Autowired
    private ITbDiyStrategyService tbDiyStrategyService;
    @Autowired
    private ITbBaseJggService tbBaseJggService;

    @RequiresPermissions("system:strategy:view")
    @GetMapping()
    public String strategy()
    {
        return prefix + "/strategy";
    }

    /**
     * 查询策略生成列表
     */
    @RequiresPermissions("system:strategy:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbDiyStrategy tbDiyStrategy)
    {
        startPage();
        List<TbDiyStrategy> list = tbDiyStrategyService.selectTbDiyStrategyList(tbDiyStrategy);
        return getDataTable(list);
    }

    /**
     * 导出策略生成列表
     */
    @RequiresPermissions("system:strategy:export")
    @Log(title = "策略生成", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbDiyStrategy tbDiyStrategy)
    {
        List<TbDiyStrategy> list = tbDiyStrategyService.selectTbDiyStrategyList(tbDiyStrategy);
        ExcelUtil<TbDiyStrategy> util = new ExcelUtil<TbDiyStrategy>(TbDiyStrategy.class);
        return util.exportExcel(list, "策略生成数据");
    }

    /**
     * 新增策略生成
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存策略生成
     */
    @RequiresPermissions("system:strategy:add")
    @Log(title = "策略生成", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbDiyStrategy tbDiyStrategy)
    {
        return toAjax(tbDiyStrategyService.insertTbDiyStrategy(tbDiyStrategy));
    }

    /**
     * 修改策略生成
     */
    @RequiresPermissions("system:strategy:edit")
    @GetMapping("/edit/{strategyNm}")
    public String edit(@PathVariable("strategyNm") String strategyNm, ModelMap mmap)
    {
        TbDiyStrategy tbDiyStrategy = tbDiyStrategyService.selectTbDiyStrategyByStrategyNm(strategyNm);
        mmap.put("tbDiyStrategy", tbDiyStrategy);
        return prefix + "/edit";
    }

    /**
     * 修改保存策略生成
     */
    @RequiresPermissions("system:strategy:edit")
    @Log(title = "策略生成", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbDiyStrategy tbDiyStrategy)
    {
        return toAjax(tbDiyStrategyService.updateTbDiyStrategy(tbDiyStrategy));
    }

    /**
     * 删除策略生成
     */
    @RequiresPermissions("system:strategy:remove")
    @Log(title = "策略生成", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbDiyStrategyService.deleteTbDiyStrategyByStrategyNms(ids));
    }

    @RequestMapping("/find/{dimensionCd}")
    @ResponseBody
    public List<TbBaseCustomIndexDef> findByDimensionCd(@PathVariable("dimensionCd") String dimensionCd, ModelMap mmap)
    {
        TbBaseJgg tbBaseJgg = tbBaseJggService.selectTbBaseJggByDimensionCd(dimensionCd);
        return tbBaseJgg.getTbBaseCustomIndexDefList();
    }
}
